package com.ggh.jinjilive.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.blankj.utilcode.util.ToastUtils;
import com.ggh.jinjilive.BaseApplication;
import com.ggh.jinjilive.R;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.youth.banner.util.LogUtils;


public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wxpay_entry);
        BaseApplication.getInstance().iwxapi.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        BaseApplication.getInstance().iwxapi.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {
        LogUtils.d("goPayWx onReq");
    }

    @Override
    public void onResp(BaseResp resp) {
        LogUtils.d("goPayWx onResp errStr=" + resp.errStr + " openId=" + resp.openId + " transaction=" + resp.transaction + " errCode=" + resp.errCode);
        if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            if (resp.errCode == 0) {
                ToastUtils.make().show("支付成功");
            } else {
                ToastUtils.make().show("支付失败");
            }
            finish();
        }

    }
}

